package com.seven.commons.excel.easyexcel;

import com.alibaba.excel.metadata.Font;
import com.alibaba.excel.metadata.Sheet;
import com.alibaba.excel.metadata.TableStyle;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.poi.ss.usermodel.IndexedColors;

import java.util.Objects;

/**
 * @工程名:common-utils
 * @author: sevenDay
 * @时间: 2019/1/7 11:06
 * @描述:
 */
@Data
@AllArgsConstructor
public class ExcelStyleModel {

    private boolean bold;

    private Integer backColor;

    private short fontHeight;

    private String fontName;

    /**
     * @descrp:设置table的head的样式
     * @auther: sevenDay
     * @date: 2019/1/7 13:11
     * @param excelStyleModel :
     * @param sheet :
     * @return : void
     */
    public static void setSheetHeadStyle(ExcelStyleModel excelStyleModel, Sheet sheet){
        if (Objects.isNull(excelStyleModel)){
            return;
        }
        TableStyle tableStyle = new TableStyle();
        Font font = new Font();
        font.setFontName(excelStyleModel.getFontName());
        font.setFontHeightInPoints(excelStyleModel.getFontHeight());
        font.setBold(excelStyleModel.isBold());
        tableStyle.setTableContentBackGroundColor(IndexedColors.fromInt(excelStyleModel.getBackColor()));
        tableStyle.setTableContentFont(font);
        sheet.setTableStyle(tableStyle);
    }
    /**
     * @descrp:设置表格内容的背景和样式
     * @auther: sevenDay
     * @date: 2019/1/7 13:12
     * @param excelStyleModel :
     * @param sheet :
     * @return : void
     */
    public static void setSheetContentStyle(ExcelStyleModel excelStyleModel, Sheet sheet){
       setSheetHeadStyle(excelStyleModel,sheet);
    }

}
